package com.ruoyi.web.controller.bl;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bl.domain.BlOrderGoods;
import com.ruoyi.bl.service.IBlOrderGoodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单商品Controller
 * 
 * @author ruoyi
 * @date 2023-08-11
 */
@RestController
@RequestMapping("/bl/orderGoods")
public class BlOrderGoodsController extends BaseController
{
    @Autowired
    private IBlOrderGoodsService blOrderGoodsService;

    /**
     * 查询订单商品列表
     */
    @PreAuthorize("@ss.hasPermi('bl:orderGoods:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlOrderGoods blOrderGoods)
    {
        startPage();
        List<BlOrderGoods> list = blOrderGoodsService.selectBlOrderGoodsList(blOrderGoods);
        return getDataTable(list);
    }

    /**
     * 导出订单商品列表
     */
    @PreAuthorize("@ss.hasPermi('bl:orderGoods:export')")
    @Log(title = "订单商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlOrderGoods blOrderGoods)
    {
        List<BlOrderGoods> list = blOrderGoodsService.selectBlOrderGoodsList(blOrderGoods);
        ExcelUtil<BlOrderGoods> util = new ExcelUtil<BlOrderGoods>(BlOrderGoods.class);
        util.exportExcel(response, list, "订单商品数据");
    }

    /**
     * 获取订单商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('bl:orderGoods:query')")
    @GetMapping(value = "/{orderGoodsId}")
    public AjaxResult getInfo(@PathVariable("orderGoodsId") Long orderGoodsId)
    {
        return success(blOrderGoodsService.selectBlOrderGoodsByOrderGoodsId(orderGoodsId));
    }

    /**
     * 新增订单商品
     */
    @PreAuthorize("@ss.hasPermi('bl:orderGoods:add')")
    @Log(title = "订单商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlOrderGoods blOrderGoods)
    {
        blOrderGoods.setCreateBy(getUsername());
        return toAjax(blOrderGoodsService.insertBlOrderGoods(blOrderGoods));
    }

    /**
     * 修改订单商品
     */
    @PreAuthorize("@ss.hasPermi('bl:orderGoods:edit')")
    @Log(title = "订单商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlOrderGoods blOrderGoods)
    {
        blOrderGoods.setUpdateBy(getUsername());
        return toAjax(blOrderGoodsService.updateBlOrderGoods(blOrderGoods));
    }

    /**
     * 删除订单商品
     */
    @PreAuthorize("@ss.hasPermi('bl:orderGoods:remove')")
    @Log(title = "订单商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderGoodsIds}")
    public AjaxResult remove(@PathVariable Long[] orderGoodsIds)
    {
        return toAjax(blOrderGoodsService.deleteBlOrderGoodsByOrderGoodsIds(orderGoodsIds));
    }
}
